import axios from 'axios'
import { MessageBox, Message } from 'element-ui'
import router from "@/router";

// create an axios instance
// https://www.axios-http.cn/docs/req_config
const service = axios.create({
  // baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  // `baseURL` 将自动加在 `url` 前面，除非 `url` 是一个绝对 URL。它可以通过设置一个 `baseURL` 便于为 axios 实例的方法传递相对 URL
  // withCredentials: true, // send cookies when cross-domain requests
  // timeout: 5000, // request timeout
  traditional: true,
  transformRequest: [
    function(data) {
      let ret = ''
      for (let it in data) {
        ret +=
          encodeURIComponent(it) +
          '=' +
          encodeURIComponent(data[it]) +
          '&'
      }
      return ret
    }
  ]
});



export default service
